package gui;
import javax.swing.*;
import javax.swing.border.EmptyBorder;

import model.Charts;
import model.PrintImage;

import org.jfree.ui.RefineryUtilities;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class tab7 extends JPanel implements ActionListener {

	private JButton print, b1,b2,b3,b4;
	private JLabel l1, chart1, chart2, chart3;
	private JComboBox estate;
	private JPanel p1,p2, p2a, p2b;
	public static String selectForPrint;
	
	
	String estates[] = {"Estate 1", "Estate 2"};
	
	public tab7() {
		this.setPreferredSize(new Dimension(795, 395));
		this.setLayout(new BorderLayout());
		
		//EAST panel 
		
		p1 = new JPanel();
		p1.setLayout(new FlowLayout());
		p1.setPreferredSize(new Dimension(500, 300));
		
		
		//Charts.numCustBarChart();
		//Charts.orederPerDayBarChart();
		//Charts.deliveryTotalBarChart();
		ImageIcon logo1 = new ImageIcon("src/files/chart1.jpg");		
		chart1 = new JLabel(logo1);
		ImageIcon logo2 = new ImageIcon("src/files/chart2.jpg");		
		chart2 = new JLabel(logo2);
		ImageIcon logo3 = new ImageIcon("src/files/chart3.jpg");		
		chart3 = new JLabel(logo3);
		
		
		Charts.supplier();
        p1.add(chart1);
		
	
		
		//WEST Panel
        p2 = new JPanel();
		
		p2.setSize(new Dimension(245, 295));
		
		
		

		
		p2a = new JPanel(new GridLayout(4,2,5,5));
		
		p2a.setSize(new Dimension(245, 200));
		p2a.setBorder(new EmptyBorder(80,0,0,50));
		
		print = new JButton("Print");
		print.addActionListener(this);
		b1 = new JButton("Chart 1");
		b1.addActionListener(this);
		b2 = new JButton("Chart 2");
		b2.addActionListener(this);
		b3 = new JButton("chart 3");
		b3.addActionListener(this);
		b4 = new JButton("Button 4");
		b4.addActionListener(this);
		l1 = new JLabel("Choose estate: ");
		estate = new JComboBox<>(estates);
	
		
		
		
		p2a.add(l1); 
		p2a.add(estate);
		p2a.add(b1);
		p2a.add(b2);
		p2a.add(b3);
		p2a.add(b4);
		//p2a.add(b5);
		//p2a.add(Box.createRigidArea(new Dimension(0,250)));
		p2a.add(print);
		//p2.add(p2b, BorderLayout.NORTH);
		p2.add(p2a);
		
		
		this.add(p1, BorderLayout.WEST);
		this.add(p2, BorderLayout.EAST);
		

	}

	@Override
	public void actionPerformed(ActionEvent ae) {
		if(ae.getSource()== b1)
		{
			selectForPrint = "src/files/chart1.jpg";
			Charts.supplier();
			p1.remove(chart1);
			p1.remove(chart2);
			p1.remove(chart3);
			p1.add(chart1);	
			p1.repaint();
			p1.revalidate();
			
		}
		if(ae.getSource()== b2)
		{
			selectForPrint = "src/files/chart2.jpg";
			Charts.numCustBarChart();
			p1.remove(chart1);
			p1.remove(chart2);
			p1.remove(chart3);
			p1.add(chart2);
			p1.repaint();
			p1.revalidate();
			
			
			
		}
		if(ae.getSource()== b3)
		{
			selectForPrint = "src/files/chart3.jpg";
			Charts.orederPerDayBarChart();
			p1.remove(chart1);
			p1.remove(chart2);
			p1.remove(chart3);
			p1.add(chart3);
			p1.repaint();
			p1.revalidate();
		}
		if(ae.getSource()== b4)
		{
			p1.remove(chart1);
			p1.remove(chart2);
			p1.remove(chart3);
			p1.repaint();
			p1.revalidate();
		}
		
		if(ae.getSource()== print){
			try {
				PrintImage.printer();
			} 
			catch (Exception e) {
				e.printStackTrace();
			}
		}
		
	}
}
